<template>
  <div class="ebook-reader">
    <div id="read">

    </div>
  </div>
</template>
<script>
import Epub from 'epubjs'
import { mapGetters } from 'vuex'
global.ePub = Epub
export default {
  computed: {
    ...mapGetters(['fileName'])
  },
  methods: {
    initEpub() {
      const url = 'http://192.168.0.101:4399/' + this.fileName + '.epub'
      this.book = new Epub(url)
      this.rendition = this.book.renderTo('read', {
          width: innerWidth,
          height: innerHeight,
          method: 'default'
      })
      this.rendition.display()
      console.log(this.rendition)
      this.rendition.on('touchstart', e => {
          console.log(e)
      })
      this.rendition.on('touchend', event => {
          console.log(event)
      })
    }
  },
  mounted() {
    this.$store
      .dispatch('setFilename', this.$route.params.fileName.split('|').join('/'))
      .then(() => {
        this.initEpub()
      })
  }
}
</script>
<style lang="scss" scoped>
</style>
